﻿using System;
using System.Linq;
using System.Web.Mvc;

namespace Agile.Redsys.Web.Mvc.Controllers
{
    /// <summary>
    /// Controller that receives Redsys notifications.
    /// </summary>
    public class RedsysController : Controller
    {
        /// <summary>
        /// Actions that receives Redsys notifications.
        /// </summary>
        /// <param name="lcn">Redsys notification.</param>
        /// <returns>Status code 200.</returns>
        public ActionResult Callback(RedsysNotification lcn)
        {
            Commerce commerce =
                CommerceManager.List.SingleOrDefault(x => x.MerchantCode == Convert.ToInt32(lcn.MerchantCode) && x.Terminal == lcn.Terminal);

            if(commerce != null)
                commerce.RaiseNotificationReceived(lcn);

            return new HttpStatusCodeResult(200);
        }

    



    }
}
